﻿using IM.Easy.Core.AppContext;
using IM.Easy.Core.Utils;
using Microsoft.AspNetCore.Mvc.Filters;

namespace IM.Easy.Api.Filters
{
    public class SuperAdminAttribute : ActionFilterAttribute
    {
        public string Message { get; set; }
        public SuperAdminAttribute() { }

        public SuperAdminAttribute(string message)
        {
            Message = message;
        }

        public override void OnActionExecuting(ActionExecutingContext context)
        {
            var message = string.IsNullOrEmpty(Message) ? "仅超管才能操作此类数据" : Message;
            if (!ImApp.User.IsSuperAdmin) ExceptionUtils.ThrowBusinessException(message);
            base.OnActionExecuting(context);
        }
    }
}
